package com.freight.user.controller;

import com.freight.core.common.utils.ResultUtil;
import com.freight.core.common.vo.Result;
import com.freight.file.vo.PicFileVo;
import com.freight.user.dto.IdCardDto;
import com.freight.user.entity.IdCard;
import com.freight.user.service.IdCardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author huyingtai
 */
@Slf4j
@RestController
@Api(description = "身份证管理接口")
@RequestMapping("/freight/idCard")
@Transactional
public class UserIdCardController {

    @Autowired
    private IdCardService idCardService;

    @RequestMapping(value = "/uploadIdCardPic", method = RequestMethod.POST)
    @ApiOperation(value = "解析身份证正面信息")
    public Result<PicFileVo> getIdCardFaceInfo(@RequestParam(required = false) MultipartFile file, String fileType, Long userId) {
        PicFileVo res = idCardService.upLoadIdCard(file, fileType, userId);
        return ResultUtil.data(res);
    }

    @RequestMapping(value = "/getIdCarDInfo", method = RequestMethod.POST)
    @ApiOperation(value = "获取身份证信息")
    public Result<IdCard> getIdCarDInfo(Long userId) {
        IdCard res = idCardService.getIdCarDInfo(userId);
        return ResultUtil.data(res);
    }


}
